<%@ page pageEncoding="utf-8" contentType="text/html" %>
<%@ page import="core.Tool, model.*" %>
<%
ChoiceQuestion q = (ChoiceQuestion) request.getAttribute("question");
String[] options = q.getOptions();
Object[] question_types = (Object[]) request.getAttribute("question_types[]");
int pid = Tool.intval(request.getParameter("pid"));
%>

<%@ include file="header.tpl.jsp"%>

<div class="box">
	<h2>添加/修改问题</h2>
	<form action="EditQuestion" method="post">
		<input type="hidden" id="qid" name="qid" value="<%=q.getQid()%>" />
		<table>
			<tr>
				<th>问题描述:</th>
				<td><input type="text" id="content" name="content" value="<%=q.getContent()%>" /></td>
			</tr>
			<tr>
				<th>问题类型:</th>
				<td>
					<select id="qtid" name="qtid">
					<%for(int i = 0; i < question_types.length;i++){%>
					<%QuestionType qt = (QuestionType) question_types[i];%>
						<option value="<%=qt.getQtid()%>"><%=qt.getName()%></option>
					<%}%>
					</select>
				</td>
			</tr>
			<tr>
				<th>正确答案:</th>
				<td><input type="text" id="answer" name="answer" value="<%=q.getAnswer()%>" /></td>
			</tr>
			<tr>
				<th>选项:</th>
				<td>
					<table>
						<thead><tr><td>Option</td><td>Operation</td></tr></thead>
						<%for(int i = 0; i < options.length; i++){%>
						<tr>
							<td><input type="text" id="options[]" name="options[]" value="<%=options[i]%>" /></td>
							<td><a href="#" onclick="createNode(this)">[Add]</a><a href="#" onclick="removeNode(this)">[Remove]</a></td>
						</tr>
						<%}%>
					</table>
				</td>
			</tr>
		</table>
		<%if(pid > 0){%><input type="hidden" id="pid" name="pid" value="<%=pid%>" /><%}%>
		<div class="post_buttons">
			<button type="submit">完成</button>
		</div>
	</form>
</div>

<%@ include file="footer.tpl.jsp"%>